<?php
/**
 * tenders actions.
 *
 * @package    IPLIFE
 * @subpackage tenders
 * @author     alexey.shapran@gmail.com
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class eventsActions extends sfActions
{
	public function executeIndex(sfWebRequest $request)
	{
		$this->pager = new sfDoctrinePager('Event', sfConfig::get('app_max_per_page'));

		$query = Doctrine_Query::create()
    				->from("event t")
    				->orderBy("tender_date DESC")
    				->leftJoin("t.Region region");

		$this->pager->setQuery($query);
		$this->pager->setPage($request->getParameter('page', 1));
		$this->pager->init();

    	// Get list of регионов
    	$query = Doctrine_Query::create()
    				->from("region")
    				->orderBy("name");

    	$this->Region = '';
    	$this->regions = $query->execute();
    	
        $response = $this->getResponse();
		$response->addMeta('keywords', SettingsData::Get_it(SettingsData::EV_KEY));
		$response->addMeta('description', SettingsData::Get_it(SettingsData::EV_DESC));
		$response->setTitle(sfConfig::get('app_title')." | ".SettingsData::Get_it(SettingsData::EV_TITLE)  );
    	
	}

	public function executeView(sfWebRequest $request)
	{
		$this->tender = $this->getRoute()->getObject();
		$this->forward404Unless($this->tender);
	}

	public function executeRegion(sfWebRequest $request)
	{
		$this->pager = new sfDoctrinePager('Event', sfConfig::get('app_max_per_page'));

    	$query = Doctrine_Query::create()
    				->from("event t")
    				->orderBy("tender_date DESC")
    				->leftJoin("t.Region region")
    				->where("t.region_id = ?",array($request->getParameter('region_id')))
    				->limit(20);

    	$this->pager->setQuery($query);
		$this->pager->setPage($request->getParameter('page', 1));
		$this->pager->init();

		$this->Region = Doctrine::getTable('Region')->findOneBy('id',$request->getParameter('region_id'));
		$this->forward404Unless($this->Region);

    	//$this->tenders = $query->execute();
    	$this->setTemplate('index');

		//Get list of regions
    	$query = Doctrine_Query::create()
    				->from("region")
    				->orderBy("name");
    	$this->regions = $query->execute();
	}
}